<template>
  <div class="container">
    <h3 class="title"><span />回收站</h3>
    <el-table
      :data="recycleData"
      border
      stripe
      :header-cell-style="{'text-align':'center',}"
      :cell-style="{'text-align':'center'}"
      @selection-change="handleSelectionChange"
    >
      <el-table-column prop="id" label="ID" width="100px" />
      <el-table-column prop="title" label="内容名称" />
      <el-table-column prop="table_name" label="内容类型" />
      <el-table-column prop="name" label="操作人" />
      <el-table-column label="操作" fixed="right" width="200px">
        <template slot-scope="scope">
          <el-button type="primary" size="mini" @click="restore(scope.row)">恢复</el-button>
          <el-button class="dele" size="mini" @click="del(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :current-page="page.currentPage"
      :page-sizes="page.pageSizes"
      :page-size="page.size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="page.total"
      :hide-on-single-page="page.total<page.size?true:false"
      style="margin-top:20px"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
import recycleApi from '@/api/recycle'
export default {
  data() {
    return {
      recycleData: [],
      ids: [],
      page: {
        total: 0,
        currentPage: 1,
        size: 10,
        pageSizes: [10, 20, 30, 40]
      } // 分页器
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 多选
    handleSelectionChange(val) {
      this.ids = val
    },
    // 回收站列表
    getList() {
      const val = {
        limit: this.page.size,
        page: this.page.currentPage
      }
      recycleApi.recycleList(val).then(res => {
        this.recycleData = res.data
        this.page.total = res.count
      })
    },
    // 还原
    restore(row) {
      recycleApi.recycleRestore({ id: row.id }).then(res => {
        if (res.code == 0) {
          this.$message.success(res.msg)
          this.getList()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 批量还原
    allRestore() {
      recycleApi.recycleRestoreAll({ ids: this.ids }).then(res => {
        if (res.code == 0) {
          this.$message.success(res.msg)
          this.getList()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 删除
    del(row) {
      this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        recycleApi.recycledel({ id: row.id }).then(res => {
          if (res.code == 0) {
            this.$message.success(res.msg)
            this.getList()
          } else {
            this.$message.error(res.msg)
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    // 分页规格改变
    handleSizeChange(val) {
      this.page.size = val
      this.page.currentPage = 1
      this.getList()
    },
    // 分页点击
    handleCurrentChange(val) {
      this.page.currentPage = val
      this.getList()
    }
  }
}
</script>

<style scoped>

</style>
